package com.example.project.projectspringcloud.service.impl.order;

import com.example.project.projectspringcloud.dao.order.OrderDetailMapper;
import com.example.project.projectspringcloud.dao.user.UserMapper;
import com.example.project.projectspringcloud.dao.video.VideoMapper;
import com.example.project.projectspringcloud.entity.Page;
import com.example.project.projectspringcloud.entity.order.OrderDetail;
import com.example.project.projectspringcloud.entity.user.User;
import com.example.project.projectspringcloud.entity.video.Video;
import com.example.project.projectspringcloud.service.BaseService;
import com.example.project.projectspringcloud.service.order.OrderDetailService;
import com.example.project.projectspringcloud.service.video.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class OrderDetailServiceImpl extends BaseService<OrderDetail, OrderDetailMapper> implements OrderDetailService {

    @Autowired
    private VideoMapper videoMapper;

    @Autowired
    private VideoService videoService;

    @Autowired
    private UserMapper userMapper;

    @Override
    public OrderDetail get(OrderDetail orderDetail) {
        OrderDetail exist = super.mapper.selectOne(orderDetail);
        if (exist != null) {
            if (exist.getSameStyleId() != null) {
                exist.setSameStyle(videoService.get(new Video(exist.getSameStyleId())));
            }

            if (exist.getPhotographer() != null) {
                exist.setPhotoGrapherUser(userMapper.selectOneWithPrivate(new User(exist.getPhotographer())));
            }

            if (exist.getScriptwriter() != null) {
                exist.setScriptWriterUser(userMapper.selectOneWithPrivate(new User(exist.getScriptwriter())));
            }
        }
        return exist;
    }

    @Override
    public List<OrderDetail> list(Page page, OrderDetail orderDetail) {
        return super.list(null, orderDetail);
    }

    @Override
    public boolean save(OrderDetail orderDetail) {
        return super.save(orderDetail);
    }

    @Override
    public boolean delete(Integer[] ids) {
        return super.delete(ids);
    }
}
